package com.rc.saas.tenant.service.hlhtsk;

import com.rc.saas.tenant.mapper.hlhtsk.HlhtskTenantMapper;
import com.rc.saas.tenant.model.hlhtsk.HlhtskTenant;
import com.rc.saas.tenant.model.hlhtsk.HlhtskTenantExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
public class HlhtskTenantServiceImpl implements HlhtskTenantService {

    @Autowired
    private HlhtskTenantMapper hlhtskTenantMapper;

    @Override
    public HlhtskTenantMapper getMapper() {
        return hlhtskTenantMapper;
    }

    @Override
    public HlhtskTenant selectByTenantCode(String tenantCode) {
        HlhtskTenantExample example = new HlhtskTenantExample();
        example.createCriteria().andTenantCodeEqualTo(tenantCode).andTenantHlhtTypeEqualTo("0").andStatusEqualTo("0");
        List<HlhtskTenant> hlhtskTenants = hlhtskTenantMapper.selectByExample(example);
        return hlhtskTenants.size() > 0 ? hlhtskTenants.get(0) : null;
    }

    @Override
    public HlhtskTenant selectHlhtTenantCode(String tenantCode, String hlhtTenantCode) {
        //状态(0正常 1停用) 默认 0
        HlhtskTenantExample example = new HlhtskTenantExample();
        example.createCriteria().andTenantCodeEqualTo(tenantCode).andHlhtTenantCodeEqualTo(hlhtTenantCode).andStatusEqualTo("0");
        List<HlhtskTenant> list = hlhtskTenantMapper.selectByExample(example);
        if (!CollectionUtils.isEmpty(list)) {
            return list.get(0);
        }
        return null;
    }
}
